var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2001-2007/VanDyke-Heavenly%20Purpose%20In%20Earthly%20Trials.mp3",
	"../AUDIO/2001-2007/Jenkins-Doing%20Nothing%20In%20the%20Name%20of%20Something.mp3",
	"../AUDIO/2001-2007/09.29.06%20AM%20MCNEESE%20BIG%20WATER.mp3",
	"../AUDIO/2001-2007/09.30.06%20AM%20MCNEESE%20BARREN%20WATER.mp3",
	"../AUDIO/2001-2007/09.30.06%20PM%20MCNEESE%20BITTER%20AND%20BLESSED%20WATER.mp3",
	"../AUDIO/2001-2007/09.30.06%20AM%20MARK%20THRIFT%20JESUS%20STOOD%20STILL.mp3",
	"../AUDIO/2001-2007/Melvin%20Biggs%20-%20%20Grace,%20It%27s%20Amazing.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

    $("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
        playNextItem();
    });
    
    for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

    selectItem(document.getElementById("player-item-0"));
});
